/*     */ package com.zimbra.cs.index;
/*     */ 
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.Log.Level;
/*     */ import java.io.IOException;
/*     */ import java.io.OutputStream;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class LoggingOutputStream
/*     */   extends OutputStream
/*     */ {
/*     */   private static final byte CR = 13;
/*     */   private static final byte LF = 10;
/*     */   private static final int DEFAULT_BUFFER_LENGTH = 2048;
/*     */   private static final int MAX_BUFFER_LENGTH = 16384;
/*  30 */   protected boolean mClosed = false;
/*  31 */   private Log mLog = null;
/*  32 */   private Log.Level mLevel = null;
/*     */   
/*     */   protected int bytesInBuf;
/*     */   protected byte[] buf;
/*     */   private int bufLength;
/*     */   
/*     */   LoggingOutputStream(Log log, Log.Level level)
/*     */   {
/*  40 */     this.bufLength = 2048;
/*  41 */     this.buf = new byte['ࠀ'];
/*  42 */     this.bytesInBuf = 0;
/*  43 */     this.mLog = log;
/*  44 */     this.mLevel = level;
/*     */   }
/*     */   
/*     */   public void close()
/*     */   {
/*  49 */     flush();
/*  50 */     this.mClosed = true;
/*     */   }
/*     */   
/*     */   public void write(int in) throws IOException
/*     */   {
/*  55 */     if (this.mClosed) {
/*  56 */       throw new IOException("Stream closed.");
/*     */     }
/*     */     
/*  59 */     if (in != 0)
/*     */     {
/*     */ 
/*  62 */       if (this.bytesInBuf == this.bufLength)
/*     */       {
/*  64 */         if (this.bufLength * 2 >= 16384) {
/*  65 */           flush();
/*     */         }
/*     */         else {
/*  68 */           int newBufLength = 2 * this.bufLength;
/*  69 */           byte[] newBuf = new byte[newBufLength];
/*  70 */           System.arraycopy(this.buf, 0, newBuf, 0, this.bufLength);
/*  71 */           this.buf = newBuf;
/*  72 */           this.bufLength = newBufLength;
/*     */         }
/*     */       }
/*  75 */       this.buf[this.bytesInBuf] = ((byte)in);
/*  76 */       this.bytesInBuf += 1;
/*     */       
/*     */ 
/*  79 */       if (in == 10) {
/*  80 */         flush();
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void flush() {
/*  86 */     if (this.bytesInBuf > 0)
/*     */     {
/*     */ 
/*  89 */       if (((this.bytesInBuf == 1) && (this.buf[0] == 10)) || ((this.bytesInBuf == 2) && (this.buf[0] == 13) && (this.buf[1] == 10)))
/*     */       {
/*  91 */         this.bytesInBuf = 0;
/*     */       }
/*     */       
/*  94 */       byte[] toPrint = new byte[this.bytesInBuf];
/*  95 */       System.arraycopy(this.buf, 0, toPrint, 0, this.bytesInBuf);
/*     */       
/*  97 */       switch (this.mLevel) {
/*     */       case error: 
/*  99 */         this.mLog.error(toPrint);
/* 100 */         break;
/*     */       case warn: 
/* 102 */         this.mLog.warn(toPrint);
/* 103 */         break;
/*     */       case info: 
/* 105 */         this.mLog.info(toPrint);
/* 106 */         break;
/*     */       case debug: 
/*     */       default: 
/* 109 */         this.mLog.debug(toPrint);
/*     */       }
/*     */       
/* 112 */       this.bytesInBuf = 0;
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/index/LoggingOutputStream.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */